<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<link rel="stylesheet" type="text/css" href="../public/css/index.css" />
		<title>健康平台</title>
		<style type="text/css">
			body {
				background: #f9f9f9;
			}
		</style>
	</head>
	<body>
		<div id="example">
			<div style="height: 2.8rem;line-height: 2.8rem;color: #fff;font-size: 1.02rem;text-align: center;background: #107e34;">
				{{title}}
			</div>
			<div class="h_lists" v-if="obj">
				<span @click="tabHeader" v-for="(item,index) in obj.child" :class="dataIndex==index?'spanCkH':''" :data-index="index"
				 :key="item.id">
					{{item.name}}
				</span>
			</div>
			<div class="zxLists" v-if="dataObj.length>0">
				<a v-for="item,index in dataObj" :key="item.Id" class="zxList" :href="'detail.html?id='+item.Id+'&title='+title">
					<div class="zxListTitle textOver">
						{{item.FullHead}}
					</div>
					<div class="zxListIcon">
						<div class="zxListIconTime">
							<i></i>{{formatDate(item.FabuDate)}}
						</div>
						<div class="zxListIconLy textOver" v-show="item.faburen">
							<i></i>{{item.faburen}}
						</div>
						<i class="zxListDetail"></i>
						<div style="clear: both;float: none;"></div>
					</div>
				</a>

			</div>
		</div>

		<script src="../public/script/plug/jquery-3.3.1.min.js"></script>
		<script src="../public/script/plug/vue.js"></script>
		<script src="../public/script/plug/common.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="../public/script/plug/layer/layer.js"></script>
		<script>
			function getUrl() {
				let url = decodeURI(location.href).split('?')[1];
				if (url) {
					let obj = {};
					let u = url.split('&');
					for (let i in u) {
						obj[u[i].split('=')[0]] = u[i].split('=')[1];
					}
					return obj;
				} else {
					return false;
				}
			}
			let objUrl = getUrl();
			if (objUrl && objUrl.title) {
				document.title = objUrl.title;
			} else {
				document.title = '详情';
			}

			var data = {
				title: objUrl.title || '详情',
				rows: 10,
				page: 1,
				dataIndex: 0, //当前选中分类状态
				listsType: {
					'健康宣教': {
						id: '100d58b2-2a79-4160-aa08-438efa1be653',
						url: '/home/list2',
						cs: 'firstnodeid',
						child: [{
							name: '健康宣教',
							id: '100d58b2-2a79-4160-aa08-438efa1be653',
							url: '/home/list2',
							cs: 'firstnodeid',
						},
						{
							id: '99339C62-2D24-420D-834F-A3569661BEDE',
							name: '资料下载',
							url: '/home/getpagelist',
							cs: 'secondnodeid'
						}
						]
					},'健康常识': {
						id: '100d58b2-2a79-4160-aa08-438efa1be653',
						url: '/home/list2',
						cs: 'firstnodeid',
						child: [
							{
								name: '健康常识',
								id: '100d58b2-2a79-4160-aa08-438efa1be653',
								url: '/home/list2',
								cs: 'firstnodeid',
							}
							,{
							id: 'f0705b9a-8bc6-4dae-9822-1bc55b770369',
							name: '健康素养',
							url: '/home/getpagelist2',
							cs: 'secondnodeid'
						}]
					},'教育培训': {
						id: '100d58b2-2a79-4160-aa08-438efa1be653',
						url: '/home/list2',
						cs: 'firstnodeid',
						child: [
							{
								name: '招生信息',
								id: '58F8C664-2516-44F1-93B8-19FFF39A9BD3',
								url: '/home/getpagelist2',
								cs: 'secondnodeid',
							}
							,{
							id: '9B4347D3-4274-4AC4-986F-ADEF0B29CAF1',
							name: '培训班',
							url: '/home/getpagelist2',
							cs: 'secondnodeid'
						}]
					},'心理健康': {
						id: '74C15D75-5608-4699-AF13-A865E90CBD05',
						url: '/home/getpagelist2',
						cs: 'secondnodeid',
						child: [
							{
								name: '健康知识',
								id: '74C15D75-5608-4699-AF13-A865E90CBD05',
								url: '/home/getpagelist2',
								cs: 'secondnodeid',
							}
							,{
							id: '9B4347D3-4274-4AC4-986F-ADEF0B29CAF1',
							name: '咨询预约',
							link:'/xlzxapi/wx_index',
							url: '/home/getpagelist2',
							cs: 'secondnodeid'
						}]
					},

				},
				obj: {}, //当前分类总数据
				objRq: {}, //当前二级分类id url 信息
				dataObj: []
			};
			var vm = new Vue({
				el: '#example',
				data: data,
				mounted() {
					this.autoPage();
					window.addEventListener('scroll', this.handleScroll)
				},
				methods: {
					formatDate(time) {
						return formatDate(time, 'yyyy-MM-dd')
					}, //时间处理
					handleScroll: function(el) {
						if($(window).scrollTop()+$(window).height()>=$(document).height()){
							this.page=this.page+=1;
							this.getDate(this);
						}
					}, //滚动监听
					autoPage: function() {
						let that = this;
						that.obj = that.listsType[objUrl.title];
						that.objRq = that.obj.child[0];
						this.getDate(this);
					}, //初始化参数
					getDate: function(that) {
						let da = {};
						da[that.objRq.cs] = that.objRq.id;
						da.rows = that.rows;
						da.page = that.page;
						$.ajax({
							url: apiUrl()+that.objRq.url,
							type: 'post',
							async:false,
							data: da,
							success: function(d) {
								if (that.page > 1) {
									if (d.rt) {
										that.dataObj = that.dataObj.concat(d.rt);
									} else {
										that.dataObj = that.dataObj.concat(d.rows);
									}
								} else {
									if (d.rt) {
										that.dataObj = d.rt;
									} else {
										that.dataObj = d.rows;
									}
								}
							}
						})
					}, //获取数据
					tabHeader: function(event) {
						let index = event.target.dataset.index;
						if (index == this.dataIndex) {
							return false;
						} else {
							this.dataIndex = index;
							this.page = 1;
							if (index == 0) {
								this.objRq = this.obj;
							} else {
								this.objRq = this.obj.child[index];
							}
							if(this.objRq.link){
								window.location.href=this.objRq.link;
								return false;
							}
							this.getDate(this);

						}
					}, //切换数据
				}
			});
		</script>

	</body>
</html>
